package org.lex.ftp.ui.actions;

import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JPanel;

import org.lex.ftp.FTP;
import org.lex.ftp.ui.prefs.FileRulesPane;
import org.lex.swing.ActionBuilder;
import org.lex.swing.util.CenterSouthPane;
import org.lex.swing.util.L1TnButtons;
import org.lex.swing.widgets.EnhancedDialog;


public class FileRulesAction extends FTPAction {
	public FileRulesAction(FTP app) {
		super(app);
		this.setName("File exist rules...");
	}

	public void actionPerformed(ActionEvent e) {
		this.createAndShowDialog();
	}

	private void createAndShowDialog() {
		Window root = app.getRootWindow();
		final EnhancedDialog ed = new EnhancedDialog(root, "File exists options", true);
		// content pane
		final FileRulesPane rules = new FileRulesPane();
		L1TnButtons buttons = L1TnButtons.create(new ActionBuilder("Defaults").setActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				rules.restoreDefaults();
			}
		}), new ActionBuilder("OK").setActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				rules.saveConfiguration();
				ed.dispose();
			}
		}), new ActionBuilder("Cancel").setActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				ed.dispose();
			}
		}));
		JPanel contentPane = new CenterSouthPane(rules, buttons);
		// add to dialog
		ed.setContentPane(contentPane);
		ed.setDefaultButton(buttons.getTrailingButton(0));
		ed.setSize(475, 325);
		ed.setLocationRelativeTo(root);
		ed.setVisible(true);
	}
}
